package webservice;


import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by Zhou_Bing on 2019/4/4.
 */
public class Demo {
    public static void main(String[] args) throws IOException {

        HttpURLConnection con = (HttpURLConnection) new URL("http://106.37.170.83/codevati/webservice/VatiWebService?wsdl").openConnection();

        String soapActionString = "http://106.37.170.83/codevati/webservice/VatiWebService/service";//Soap 1.1中使用

        //有输入
        con.setDoInput(true);
        //有输出
        con.setDoOutput(true);
//        con.setRequestMethod("POST");
        con.addRequestProperty("User-Agent", "Mozilla/4.0(compatible;MSIE5.5;Windows NT; DigExt)");
        con.setRequestProperty("Content-Type", "text/xml;charset=utf-8");
        con.setRequestProperty("soapActionString",soapActionString);


        OutputStream os = con.getOutputStream();
        os.write(getSoapRequestData().getBytes());
        os.flush();
        os.close();

        /*System.out.println(con.getResponseCode());
        InputStream is = con.getErrorStream();
        InputStreamReader isr = new InputStreamReader(is,"utf-8");
        BufferedReader in = new BufferedReader(isr);
        System.out.println(in.readLine());*/
        System.out.println(con.getResponseCode());
        InputStream is = con.getErrorStream();
        byte[] buf = new byte[1024];
        int len=0;
        while((len = is.read(buf))>0){
            System.out.println(new String(buf,0,len));
        }
    }

    static String getSoapRequestData(){
        return "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://webservice.tax.com/\">\n" +
                "   <soapenv:Header/>\n" +
                "   <soapenv:Body>\n" +
                "      <web:service>\n" +
                "         <!--Optional:-->\n" +
                "         <data>test</data>\n" +
                "      </web:service>\n" +
                "   </soapenv:Body>\n" +
                "</soapenv:Envelope>";
    }
}
